﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace huaguwang.hgmanage.microblog
{
      public partial class microbolgs_E : PageBaseAdmin
      {
            #region 只读资料定义
            private readonly D_T_MicroBlogging_Exp _Dal = new D_T_MicroBlogging_Exp();

            #endregion

            #region 固定方法
            /// <summary>
            ///  设置按钮资料
            /// </summary>
            /// <param name="i"></param>
            /// <param name="but"></param>
            private void SetBut(int i, Button but)
            {
                  AdminPublic.Try(() =>
                  {
                        switch (i)
                        {
                              case 0:
                                    but.CausesValidation = false;
                                    break;
                              default:
                                    break;
                        }
                  });

            }
            /// <summary>
            /// 编辑模式的时候,填充窗口
            /// </summary>
            /// <param name="model"></param>
            private void SetControlsData(D_T_MicroBlogging_Exp.MicroBolgExp model)
            {
                  AdminPublic.Try(() =>
                  {
                        this.txtXM.Text = model.MemberName;
                        this.txtTopIs.Text = model.TopIs ? "置顶" : "不置顶";
                        this.txtState.Text = model.Deblocking ? "正常" : "冻结";
                        this.txtRemsign.Text = model.RemSign ? "推荐" : "不推荐";
                        this.txtIP.Text = model.IP.Exp_Trim();
                        this.txtAddTime.Text = model.AddDate.Exp_DateTimeTryParse().ToString();
                        this.FCKeditor1.Value = model.Topic.Exp_Trim();
                  });
            }
            #endregion



            protected void Page_Load(object sender, EventArgs e)
            {


                  AdminPublic.Try(() =>
                  {

                        if (!IsPostBack)
                        {
                              //存储主键
                              var id = Request.Params["ID"].Exp_IntTryParse();
                              ViewState.Add("ID", id);
                              if (id > 0)
                              {
                                    var model = _Dal.GetModel(id);
                                    if (model == null)
                                    {
                                          this.Exp_PageSkyAlterReplace("microbolgs.aspx", WebUserToolBar1.EditSKey, "找不到相关资料");
                                    }
                                    else
                                    {
                                          SetControlsData(model);
                                    }
                              }
                        }
                        //工具栏初始化
                        WebUserToolBar1.EditInit(
                            UserConst.Exp_GetUser,
                            UserConst.Exp_GetButtonList,
                            SetBut,
                            UserConst.Exp_ToolBarErr);
                        WebUserToolBar1.ButtonBegin("返回");
                  });

            }

            /// <summary>
            /// 按钮
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void WebUserToolBar1_Button0(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var sKey = WebUserToolBar1.EditSKey;
                        Response.Redirect("microbolgs.aspx?" + sKey);
                  });
            }
      }
}
